home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / wwbbs31_source.lha / WWBBS / Library / status_lib.c < prev    next >
C/C++ Source or Header  |  1995-06-23  |  7KB  |  212 lines

  1. #include "wwbbs.h"
  2. #include "status.h"
  3.  
  4. struct Node *GetStatusNode(BYTE *name,LONG accessmode)
  5.     {
  6.         struct Node *ret=NULL;
  7.         if(name && strlen(name))
  8.             {
  9.                 ObtainSemaphoreShared(&StatusSemaphore);
  10.                 {
  11.                     struct Node *node=NULL;
  12.                     if(node=FindName(&StatusList,name))
  13.                         {
  14.                             switch(accessmode)
  15.                                 {
  16.                                     case EXCLUSIVE_LOCK:
  17.                                         ObtainSemaphore(&(((struct StatusNode *) node)->sn_Semaphore));
  18.                                         break;
  19.                                     case SHARED_LOCK:
  20.                                     default:
  21.                                         ObtainSemaphoreShared(&(((struct StatusNode *) node)->sn_Semaphore));
  22.                                         break;
  23.                                 }
  24.                             ret=node;
  25.                         }
  26.                     else
  27.                         ReleaseSemaphore(&StatusSemaphore);
  28.                 }
  29.             }
  30.         return(ret);
  31.     }
  32.  
  33. void FreeStatusNode(struct Node *node)
  34.     {
  35.         ReleaseSemaphore(&(((struct StatusNode *) node)->sn_Semaphore));
  36.         ReleaseSemaphore(&StatusSemaphore);
  37.     }
  38.  
  39. ULONG GetStatusFields(struct Node *node,struct TagItem *tags_orig)
  40.     {
  41.         ULONG ret=0;
  42.         struct TagItem *tags;
  43.         Tag *tags_filter;
  44.         if(tags=CloneTagItems(tags_orig))
  45.             {
  46.                 tags_filter=st_tags;
  47.                 if(FilterTagItems(tags,tags_filter,TAGFILTER_AND))
  48.                     {
  49.                         struct TagItem *tstate,*tag;
  50.                         APTR data;
  51.                         tstate=tags;
  52.                         while(tag=NextTagItem(&tstate))
  53.                             {
  54.                                 data=(APTR) tag->ti_Data;
  55.                                 switch(tag->ti_Tag)
  56.                                     {
  57.                                         case STTAG_UserName:
  58.                                             strcpy((STRPTR) data,((struct StatusNode *) node)->sn_UserName);
  59.                                             break;
  60.                                         case STTAG_Location:
  61.                                             strcpy((STRPTR) data,((struct StatusNode *) node)->sn_Location);
  62.                                             break;
  63.                                         case STTAG_Prompt:
  64.                                             strcpy((STRPTR) data,((struct StatusNode *) node)->sn_Prompt);
  65.                                             break;
  66.                                         case STTAG_Stack:
  67.                                             strcpy((STRPTR) data,((struct StatusNode *) node)->sn_Stack);
  68.                                             break;
  69.                                         case STTAG_TimeRemaining:
  70.                                             *((UWORD *) data)=((struct StatusNode *) node)->sn_TimeRemaining;
  71.                                             break;
  72.                                         case STTAG_TimeUsed:
  73.                                             *((UWORD *) data)=((struct StatusNode *) node)->sn_TimeUsed;
  74.                                             break;
  75.                                         case STTAG_InactivityTimeLimit:
  76.                                             *((UWORD *) data)=((struct StatusNode *) node)->sn_InactivityTimeLimit;
  77.                                             break;
  78.                                         case STTAG_Panic:
  79.                                             *((BOOL *) data)=(((struct StatusNode *) node)->sn_Flags & STFLG_Panic) ? TRUE : FALSE;
  80.                                             break;
  81.                                         case STTAG_Local:
  82.                                             *((BOOL *) data)=(((struct StatusNode *) node)->sn_Flags & STFLG_Local) ? TRUE : FALSE;
  83.                                             break;
  84.                                         case STTAG_ConsoleOpen:
  85.                                             *((BOOL *) data)=(((struct StatusNode *) node)->sn_Flags & STFLG_ConsoleOpen) ? TRUE : FALSE;
  86.                                             break;
  87.                                         case STTAG_ANSI:
  88.                                             *((BOOL *) data)=(((struct StatusNode *) node)->sn_Flags & STFLG_ANSI) ? TRUE : FALSE;
  89.                                             break;
  90.                                         case STTAG_PageReceived:
  91.                                             *((BOOL *) data)=(((struct StatusNode *) node)->sn_Flags & STFLG_PageReceived) ? TRUE : FALSE;
  92.                                             break;
  93.                                         case STTAG_UserMonitor:
  94.                                             *((BOOL *) data)=(((struct StatusNode *) node)->sn_Flags & STFLG_UserMonitor) ? TRUE : FALSE;
  95.                                             break;
  96.                                     }
  97.                                 ret++;
  98.                             }
  99.                     }
  100.                 FreeTagItems(tags);
  101.             }
  102.         return(ret);
  103.     }
  104.  
  105. ULONG SetStatusFields(struct Node *node,struct TagItem *tags_orig)
  106.     {
  107.         ULONG ret=0,retminus=0;
  108.         struct TagItem *tags;
  109.         Tag *tags_filter=NULL;
  110.         if(tags=CloneTagItems(tags_orig))
  111.             {
  112.                 tags_filter=st_tags;
  113.                 if(FilterTagItems(tags,tags_filter,TAGFILTER_AND))
  114.                     {
  115.                         struct TagItem *tstate,*tag;
  116.                         APTR data;
  117.                         tstate=tags;
  118.                         while(tag=NextTagItem(&tstate))
  119.                             {
  120.                                 data=(APTR) tag->ti_Data;
  121.                                 switch(tag->ti_Tag)
  122.                                     {
  123.                                         case STTAG_UserName:
  124.                                             if(data && strlen((STRPTR) data)<=32)
  125.                                                 strcpy(((struct StatusNode *) node)->sn_UserName,(STRPTR) data);
  126.                                             else
  127.                                                 retminus++;
  128.                                             break;
  129.                                         case STTAG_Location:
  130.                                             if(data && strlen((STRPTR) data)<=32)
  131.                                                 strcpy(((struct StatusNode *) node)->sn_Location,(STRPTR) data);
  132.                                             else
  133.                                                 retminus++;
  134.                                             break;
  135.                                         case STTAG_Prompt:
  136.                                             if(data && strlen((STRPTR) data)<=255)
  137.                                                 strcpy(((struct StatusNode *) node)->sn_Prompt,(STRPTR) data);
  138.                                             else
  139.                                                 retminus++;
  140.                                             break;
  141.                                         case STTAG_Stack:
  142.                                             if(data && strlen((STRPTR) data)<=255)
  143.                                                 strcpy(((struct StatusNode *) node)->sn_Stack,(STRPTR) data);
  144.                                             else
  145.                                                 retminus++;
  146.                                             break;
  147.                                         case STTAG_TimeRemaining:
  148.                                             ((struct StatusNode *) node)->sn_TimeRemaining=(UWORD) data;
  149.                                             break;
  150.                                         case STTAG_TimeUsed:
  151.                                             ((struct StatusNode *) node)->sn_TimeUsed=(UWORD) data;
  152.                                             break;
  153.                                         case STTAG_InactivityTimeLimit:
  154.                                             ((struct StatusNode *) node)->sn_InactivityTimeLimit=(UWORD) data;
  155.                                             break;
  156.                                         case STTAG_Panic:
  157.                                             if((BOOL) data)
  158.                                                 ((struct StatusNode *) node)->sn_Flags|=STFLG_Panic;
  159.                                             else
  160.                                                 ((struct StatusNode *) node)->sn_Flags&=~STFLG_Panic;
  161.                                             break;
  162.                                         case STTAG_Local:
  163.                                             if((BOOL) data)
  164.                                                 ((struct StatusNode *) node)->sn_Flags|=STFLG_Local;
  165.                                             else
  166.                                                 ((struct StatusNode *) node)->sn_Flags&=~STFLG_Local;
  167.                                             break;
  168.                                         case STTAG_ConsoleOpen:
  169.                                             if((BOOL) data)
  170.                                                 ((struct StatusNode *) node)->sn_Flags|=STFLG_ConsoleOpen;
  171.                                             else
  172.                                                 ((struct StatusNode *) node)->sn_Flags&=~STFLG_ConsoleOpen;
  173.                                             break;
  174.                                         case STTAG_ANSI:
  175.                                             if((BOOL) data)
  176.                                                 ((struct StatusNode *) node)->sn_Flags|=STFLG_ANSI;
  177.                                             else
  178.                                                 ((struct StatusNode *) node)->sn_Flags&=~STFLG_ANSI;
  179.                                             break;
  180.                                         case STTAG_PageReceived:
  181.                                             if((BOOL) data)
  182.                                                 ((struct StatusNode *) node)->sn_Flags|=STFLG_PageReceived;
  183.                                             else
  184.                                                 ((struct StatusNode *) node)->sn_Flags&=~STFLG_PageReceived;
  185.                                             break;
  186.                                         case STTAG_UserMonitor:
  187.                                             if((BOOL) data)
  188.                                                 ((struct StatusNode *) node)->sn_Flags|=STFLG_UserMonitor;
  189.                                             else
  190.                                                 ((struct StatusNode *) node)->sn_Flags&=~STFLG_UserMonitor;
  191.                                             break;
  192.                                     }
  193.                                 ret++;
  194.                             }
  195.                     }
  196.                 FreeTagItems(tags);
  197.             }
  198.         ret-=retminus;
  199.         return(ret);
  200.     }
  201.  
  202. void UnLoadStatus()
  203.     {
  204.         ObtainSemaphore(&StatusSemaphore);
  205.         {
  206.             struct Node *node;
  207.             while(node=RemHead(&StatusList))
  208.                 FreeVec(node);
  209.         }
  210.         ReleaseSemaphore(&StatusSemaphore);
  211.     }
  212.